package com.superteam.zzl.Des;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.superteam.zzl.activity.R;

import java.util.List;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * Created by Administrator on 2017/1/13.
 */
public class PutongLAdapter1 extends BaseAdapter{
    private Context context;
    private List<Object>list;

    public PutongLAdapter1(Context context, List<Object> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder vh;
        if (convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(context,R.layout.putong_list_item,null);
           vh.imageView=(ImageView) convertView.findViewById(R.id.pu_lv_iv);

            vh.tv1=(TextView)convertView.findViewById(R.id.pu_lv_tv1);
            vh.tv2=(TextView)convertView.findViewById(R.id.pu_lv_tv2);
           // vh.tv2=(TextView)convertView.findViewById(R.id.ct);
          //  vh.tv3=(TextView)convertView.findViewById(R.id.content);
            //  Log.e("sda","sss");
            convertView.setTag(vh);
        }else {
            vh=(ViewHolder)convertView.getTag();
        }
        Object object=list.get(position);
        Log.e("asdf",list.size()+"Sdf");
        if (object instanceof Putong2.Data.Cms_list){

            Putong2.Data.Cms_list pdc=(Putong2.Data.Cms_list)object;
            vh.tv1.setText(pdc.title);
            vh.tv2.setText(pdc.like_count);
          //  vh.tv3.setText(pditt.content);
//           vh.imageView.setTag(pdc.cover_image);
//            new BitMapAsyncTask(context, new BitMapAsyncTask.CallBack() {
//                @Override
//                public void sendBitMap(String url, Bitmap bitmap) {
//                    if (url.equals(vh.imageView.getTag())){
//                        vh.imageView.setImageBitmap(bitmap);
//                    }
//                }
//            }).execute(pdc.cover_image);
            final BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
            Glide.with(context).load(pdc.cover_image).centerCrop().bitmapTransform(new RoundedCornersTransformation(bitmapPool,20,0)).into(new SimpleTarget<GlideDrawable>() {
                @Override
                public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                    vh.imageView.setImageDrawable(resource);
                }
            });

           // Glide.with(context).load(pdc.cover_image).skipMemoryCache(true).bitmapTransform(new RoundedCornersTransformation(bitmapPool,20,0)).into(vh.imageView);
        }

        return convertView;
    }
    class ViewHolder {
        ImageView imageView;
        // ImageView iv;
        TextView tv1,tv2;
    }
}
